package com.xh.rufongwallpaper.vo;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.util.List;

/**
 * 分页响应VO，用于前端展示
 */
@Data
public class PageResponseVO<T> {
    private List<T> data;
    private Pagination pagination;
    
    @Data
    public static class Pagination {
        @JsonProperty("current_page")
        private Integer currentPage;
        
        @JsonProperty("total_pages")
        private Integer totalPages;
        
        @JsonProperty("total_items")
        private Long totalItems;
        
        @JsonProperty("items_per_page")
        private Integer itemsPerPage;
    }
    
    public static <T> PageResponseVO<T> of(List<T> content, int page, int size, long total) {
        PageResponseVO<T> response = new PageResponseVO<>();
        response.setData(content);
        
        Pagination pagination = new Pagination();
        pagination.setCurrentPage(page + 1); // 转为1-based
        pagination.setTotalPages((int) Math.ceil((double) total / size));
        pagination.setTotalItems(total);
        pagination.setItemsPerPage(size);
        
        response.setPagination(pagination);
        return response;
    }
} 